/*
 * EventImp.cpp
 *
 *  Created on: Apr 18, 2009
 *      Author: wrice
 */

#include "DOMEventImp.h"
namespace DOMEventImp {


EventImp::EventImp(
	EventTarget * target,
	EventTarget * currentTarget,
	DOMString eventTypeArg,
	bool canBubbleArg,
	bool cancelableArg
)
: target_(target), currentTarget_(currentTarget), timeStamp_(time(0))
, eventPhase_(Event::CAPTURING_PHASE), stopPropagation_(false), preventDefault_(false)
{
	initEvent(eventTypeArg, canBubbleArg, cancelableArg);
}

void EventImp::initEvent(DOMString eventTypeArg, bool canBubbleArg, bool cancelableArg) {
	type_ = eventTypeArg;
	bubbles_ = canBubbleArg;
	cancelable_ = cancelableArg;
}

void EventImp::stopPropagation() {
	if( false == isCancelable() ) return;
	stopPropagation_ = true;
}

void EventImp::preventDefault() {
	if( false == isCancelable() ) return;
	preventDefault_ = true;
}

DOMString EventImp::getType() const {
	return type_;
}
EventTarget * EventImp::getTarget() const {
	return target_;
}
EventTarget * EventImp::getCurrentTarget() const {
	return currentTarget_;
}
unsigned short EventImp::getEventPhase() const {
	return eventPhase_;
}
bool EventImp::isBubbles() const {
	return bubbles_;
}
bool EventImp::isCancelable() const {
	return cancelable_;
}
DOMTimeStamp EventImp::getTimeStamp() const {
	return timeStamp_;
}

bool EventImp::isStopPropagation() const {
	return stopPropagation_;
}

bool EventImp::isPreventDefault() const {
	return preventDefault_;
}

void EventImp::setEventPhase(unsigned short phase) {
	eventPhase_ = phase;
}


}
